﻿using System;
using System.ComponentModel;

namespace HalconDotNet
{
	/// <summary>Represents an instance of a data container to be sent via message queues.</summary>
	// Token: 0x02000049 RID: 73
	public class HMessage : HHandle
	{
		// Token: 0x06000A04 RID: 2564 RVA: 0x0004001D File Offset: 0x0003E21D
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HMessage(IntPtr handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x06000A05 RID: 2565 RVA: 0x0004002C File Offset: 0x0003E22C
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HMessage(HHandle handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x06000A06 RID: 2566 RVA: 0x0004003B File Offset: 0x0003E23B
		private void AssertSemType()
		{
			base.AssertSemType("message");
		}

		// Token: 0x06000A07 RID: 2567 RVA: 0x00040048 File Offset: 0x0003E248
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HMessage obj)
		{
			obj = new HMessage(HHandleBase.UNDEF);
			return obj.Load(proc, parIndex, err);
		}

		// Token: 0x06000A08 RID: 2568 RVA: 0x00040060 File Offset: 0x0003E260
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HMessage[] obj)
		{
			HTuple htuple;
			err = HTuple.LoadNew(proc, parIndex, err, out htuple);
			obj = new HMessage[htuple.Length];
			for (int i = 0; i < htuple.Length; i++)
			{
				obj[i] = new HMessage(HalconAPI.IsLegacyHandleMode() ? htuple[i].IP : htuple[i].H);
			}
			htuple.Dispose();
			return err;
		}

		/// <summary>
		///   Create a new empty message.
		///   Modified instance represents: Handle of the newly created message.
		/// </summary>
		// Token: 0x06000A09 RID: 2569 RVA: 0x000400D0 File Offset: 0x0003E2D0
		public HMessage()
		{
			IntPtr proc = HalconAPI.PreCall(541);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Read a message from a file.
		///   Modified instance represents: Message handle.
		/// </summary>
		/// <param name="fileName">File name.</param>
		/// <param name="genParamName">Name of the generic parameter. Default: []</param>
		/// <param name="genParamValue">Value of the generic parameter. Default: []</param>
		// Token: 0x06000A0A RID: 2570 RVA: 0x00040114 File Offset: 0x0003E314
		public HMessage(string fileName, HTuple genParamName, HTuple genParamValue)
		{
			IntPtr proc = HalconAPI.PreCall(2164);
			HalconAPI.StoreS(proc, 0, fileName);
			HalconAPI.Store(proc, 1, genParamName);
			HalconAPI.Store(proc, 2, genParamValue);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(genParamName);
			HalconAPI.UnpinTuple(genParamValue);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Read a message from a file.
		///   Modified instance represents: Message handle.
		/// </summary>
		/// <param name="fileName">File name.</param>
		/// <param name="genParamName">Name of the generic parameter. Default: []</param>
		/// <param name="genParamValue">Value of the generic parameter. Default: []</param>
		// Token: 0x06000A0B RID: 2571 RVA: 0x0004017C File Offset: 0x0003E37C
		public HMessage(string fileName, string genParamName, string genParamValue)
		{
			IntPtr proc = HalconAPI.PreCall(2164);
			HalconAPI.StoreS(proc, 0, fileName);
			HalconAPI.StoreS(proc, 1, genParamName);
			HalconAPI.StoreS(proc, 2, genParamValue);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Query message parameters or information about the message.
		///   Instance represents: Message handle.
		/// </summary>
		/// <param name="genParamName">Names of the message parameters or info queries. Default: "message_keys"</param>
		/// <param name="key">Message keys the parameter/query should be applied to.</param>
		/// <returns>Values of the message parameters or info queries.</returns>
		// Token: 0x06000A0C RID: 2572 RVA: 0x000401D8 File Offset: 0x0003E3D8
		public HTuple GetMessageParam(string genParamName, HTuple key)
		{
			IntPtr proc = HalconAPI.PreCall(534);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, genParamName);
			HalconAPI.Store(proc, 2, key);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(key);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Query message parameters or information about the message.
		///   Instance represents: Message handle.
		/// </summary>
		/// <param name="genParamName">Names of the message parameters or info queries. Default: "message_keys"</param>
		/// <param name="key">Message keys the parameter/query should be applied to.</param>
		/// <returns>Values of the message parameters or info queries.</returns>
		// Token: 0x06000A0D RID: 2573 RVA: 0x00040238 File Offset: 0x0003E438
		public HTuple GetMessageParam(string genParamName, string key)
		{
			IntPtr proc = HalconAPI.PreCall(534);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, genParamName);
			HalconAPI.StoreS(proc, 2, key);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Set message parameter or invoke commands on the message.
		///   Instance represents: Message handle.
		/// </summary>
		/// <param name="genParamName">Names of the message parameters or action commands. Default: "remove_key"</param>
		/// <param name="key">Message keys the parameter/command should be applied to.</param>
		/// <param name="genParamValue">Values of the message parameters or action commands.</param>
		// Token: 0x06000A0E RID: 2574 RVA: 0x00040290 File Offset: 0x0003E490
		public void SetMessageParam(string genParamName, HTuple key, HTuple genParamValue)
		{
			IntPtr proc = HalconAPI.PreCall(535);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, genParamName);
			HalconAPI.Store(proc, 2, key);
			HalconAPI.Store(proc, 3, genParamValue);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(key);
			HalconAPI.UnpinTuple(genParamValue);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Set message parameter or invoke commands on the message.
		///   Instance represents: Message handle.
		/// </summary>
		/// <param name="genParamName">Names of the message parameters or action commands. Default: "remove_key"</param>
		/// <param name="key">Message keys the parameter/command should be applied to.</param>
		/// <param name="genParamValue">Values of the message parameters or action commands.</param>
		// Token: 0x06000A0F RID: 2575 RVA: 0x000402E8 File Offset: 0x0003E4E8
		public void SetMessageParam(string genParamName, string key, HTuple genParamValue)
		{
			IntPtr proc = HalconAPI.PreCall(535);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, genParamName);
			HalconAPI.StoreS(proc, 2, key);
			HalconAPI.Store(proc, 3, genParamValue);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(genParamValue);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Retrieve an object associated with the key from the message.
		///   Instance represents: Message handle.
		/// </summary>
		/// <param name="key">Key string or integer.</param>
		/// <returns>Tuple value retrieved from the message.</returns>
		// Token: 0x06000A10 RID: 2576 RVA: 0x0004033C File Offset: 0x0003E53C
		public HObject GetMessageObj(HTuple key)
		{
			IntPtr proc = HalconAPI.PreCall(536);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, key);
			HalconAPI.InitOCT(proc, 1);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(key);
			HObject result;
			num = HObject.LoadNew(proc, 1, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Retrieve an object associated with the key from the message.
		///   Instance represents: Message handle.
		/// </summary>
		/// <param name="key">Key string or integer.</param>
		/// <returns>Tuple value retrieved from the message.</returns>
		// Token: 0x06000A11 RID: 2577 RVA: 0x00040394 File Offset: 0x0003E594
		public HObject GetMessageObj(string key)
		{
			IntPtr proc = HalconAPI.PreCall(536);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, key);
			HalconAPI.InitOCT(proc, 1);
			int num = HalconAPI.CallProcedure(proc);
			HObject result;
			num = HObject.LoadNew(proc, 1, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Add a key/object pair to the message.
		///   Instance represents: Message handle.
		/// </summary>
		/// <param name="objectData">Object to be associated with the key.</param>
		/// <param name="key">Key string or integer.</param>
		// Token: 0x06000A12 RID: 2578 RVA: 0x000403E4 File Offset: 0x0003E5E4
		public void SetMessageObj(HObject objectData, HTuple key)
		{
			IntPtr proc = HalconAPI.PreCall(537);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, objectData);
			HalconAPI.Store(proc, 1, key);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(key);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
			GC.KeepAlive(objectData);
		}

		/// <summary>
		///   Add a key/object pair to the message.
		///   Instance represents: Message handle.
		/// </summary>
		/// <param name="objectData">Object to be associated with the key.</param>
		/// <param name="key">Key string or integer.</param>
		// Token: 0x06000A13 RID: 2579 RVA: 0x00040434 File Offset: 0x0003E634
		public void SetMessageObj(HObject objectData, string key)
		{
			IntPtr proc = HalconAPI.PreCall(537);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, objectData);
			HalconAPI.StoreS(proc, 1, key);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
			GC.KeepAlive(objectData);
		}

		/// <summary>
		///   Retrieve a tuple associated with the key from the message.
		///   Instance represents: Message handle.
		/// </summary>
		/// <param name="key">Key string or integer.</param>
		/// <returns>Tuple value retrieved from the message.</returns>
		// Token: 0x06000A14 RID: 2580 RVA: 0x00040480 File Offset: 0x0003E680
		public HTuple GetMessageTuple(HTuple key)
		{
			IntPtr proc = HalconAPI.PreCall(538);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, key);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(key);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Retrieve a tuple associated with the key from the message.
		///   Instance represents: Message handle.
		/// </summary>
		/// <param name="key">Key string or integer.</param>
		/// <returns>Tuple value retrieved from the message.</returns>
		// Token: 0x06000A15 RID: 2581 RVA: 0x000404D8 File Offset: 0x0003E6D8
		public HTuple GetMessageTuple(string key)
		{
			IntPtr proc = HalconAPI.PreCall(538);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, key);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Add a key/tuple pair to the message.
		///   Instance represents: Message handle.
		/// </summary>
		/// <param name="key">Key string or integer.</param>
		/// <param name="tupleData">Tuple value to be associated with the key.</param>
		// Token: 0x06000A16 RID: 2582 RVA: 0x00040528 File Offset: 0x0003E728
		public void SetMessageTuple(HTuple key, HTuple tupleData)
		{
			IntPtr proc = HalconAPI.PreCall(539);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, key);
			HalconAPI.Store(proc, 2, tupleData);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(key);
			HalconAPI.UnpinTuple(tupleData);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Add a key/tuple pair to the message.
		///   Instance represents: Message handle.
		/// </summary>
		/// <param name="key">Key string or integer.</param>
		/// <param name="tupleData">Tuple value to be associated with the key.</param>
		// Token: 0x06000A17 RID: 2583 RVA: 0x00040578 File Offset: 0x0003E778
		public void SetMessageTuple(string key, HTuple tupleData)
		{
			IntPtr proc = HalconAPI.PreCall(539);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, key);
			HalconAPI.Store(proc, 2, tupleData);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(tupleData);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>Close a message handle and release all associated resources.</summary>
		/// <param name="messageHandle">Message handle(s) to be closed.</param>
		// Token: 0x06000A18 RID: 2584 RVA: 0x000405C4 File Offset: 0x0003E7C4
		public static void ClearMessage(HMessage[] messageHandle)
		{
			HTuple htuple = HHandleBase.ConcatArray(messageHandle);
			IntPtr proc = HalconAPI.PreCall(540);
			HalconAPI.Store(proc, 0, htuple);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(htuple);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(messageHandle);
		}

		/// <summary>
		///   Close a message handle and release all associated resources.
		///   Instance represents: Message handle(s) to be closed.
		/// </summary>
		// Token: 0x06000A19 RID: 2585 RVA: 0x00040608 File Offset: 0x0003E808
		public void ClearMessage()
		{
			IntPtr proc = HalconAPI.PreCall(540);
			base.Store(proc, 0);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Create a new empty message.
		///   Modified instance represents: Handle of the newly created message.
		/// </summary>
		// Token: 0x06000A1A RID: 2586 RVA: 0x0004063C File Offset: 0x0003E83C
		public void CreateMessage()
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(541);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Read a message from a file.
		///   Modified instance represents: Message handle.
		/// </summary>
		/// <param name="fileName">File name.</param>
		/// <param name="genParamName">Name of the generic parameter. Default: []</param>
		/// <param name="genParamValue">Value of the generic parameter. Default: []</param>
		// Token: 0x06000A1B RID: 2587 RVA: 0x00040680 File Offset: 0x0003E880
		public void ReadMessage(string fileName, HTuple genParamName, HTuple genParamValue)
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(2164);
			HalconAPI.StoreS(proc, 0, fileName);
			HalconAPI.Store(proc, 1, genParamName);
			HalconAPI.Store(proc, 2, genParamValue);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(genParamName);
			HalconAPI.UnpinTuple(genParamValue);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Read a message from a file.
		///   Modified instance represents: Message handle.
		/// </summary>
		/// <param name="fileName">File name.</param>
		/// <param name="genParamName">Name of the generic parameter. Default: []</param>
		/// <param name="genParamValue">Value of the generic parameter. Default: []</param>
		// Token: 0x06000A1C RID: 2588 RVA: 0x000406E8 File Offset: 0x0003E8E8
		public void ReadMessage(string fileName, string genParamName, string genParamValue)
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(2164);
			HalconAPI.StoreS(proc, 0, fileName);
			HalconAPI.StoreS(proc, 1, genParamName);
			HalconAPI.StoreS(proc, 2, genParamValue);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Write a message to a file.
		///   Instance represents: Message handle.
		/// </summary>
		/// <param name="fileName">File name.</param>
		/// <param name="genParamName">Name of the generic parameter. Default: []</param>
		/// <param name="genParamValue">Value of the generic parameter. Default: []</param>
		// Token: 0x06000A1D RID: 2589 RVA: 0x00040744 File Offset: 0x0003E944
		public void WriteMessage(string fileName, HTuple genParamName, HTuple genParamValue)
		{
			IntPtr proc = HalconAPI.PreCall(2175);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, fileName);
			HalconAPI.Store(proc, 2, genParamName);
			HalconAPI.Store(proc, 3, genParamValue);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(genParamName);
			HalconAPI.UnpinTuple(genParamValue);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Write a message to a file.
		///   Instance represents: Message handle.
		/// </summary>
		/// <param name="fileName">File name.</param>
		/// <param name="genParamName">Name of the generic parameter. Default: []</param>
		/// <param name="genParamValue">Value of the generic parameter. Default: []</param>
		// Token: 0x06000A1E RID: 2590 RVA: 0x0004079C File Offset: 0x0003E99C
		public void WriteMessage(string fileName, string genParamName, string genParamValue)
		{
			IntPtr proc = HalconAPI.PreCall(2175);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, fileName);
			HalconAPI.StoreS(proc, 2, genParamName);
			HalconAPI.StoreS(proc, 3, genParamValue);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}
	}
}
